<template>
  <uni-table 
    border 
    stripe 
    class="optimized-table"
    :data="tableData"
  >
    <!-- 动态表头 -->
    <uni-tr>
      <uni-th 
        v-for="(header, index) in headers" 
        :key="index"
        width="70" 
        align="center" 
        class="header-cell"
      >
        {{ header.label }}
      </uni-th>
    </uni-tr>

    <!-- 动态表格数据 -->
    <uni-tr v-for="(item, index) in tableData" :key="index">
      <uni-td 
        v-for="(header, idx) in headers" 
        :key="idx"
        class="body-cell"
      >
        {{ item[header.prop] }}
      </uni-td>
    </uni-tr>
  </uni-table>
</template>

<script>
export default {
  name: 'MyTable',
  props: {
    headers: { // 表头配置
      type: Array,
      required: true,
      default: () => []
    },
    tableData: { // 表格数据
      type: Array,
      default: () => []
    }
  }
}
</script>

<style scoped>
/* 新增居中样式 */
.optimized-table ::v-deep .uni-table-th,
.optimized-table ::v-deep .uni-table-td {
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 调整原有样式 */
.optimized-table ::v-deep .uni-table-tr {
  display: flex;
  flex-wrap: nowrap;
}

.optimized-table ::v-deep .uni-table-th,
.optimized-table ::v-deep .uni-table-td {
  flex: 1;
  min-width: 100px;
  padding: 12px 8px; /* 合并padding设置 */
}

/* 保持其他原有样式 */
.optimized-table {
  font-size: 14px;
  border: 1px solid #ebeef5;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
}

.header-cell {
  background-color: #f5f7fa !important;
  color: #303133;
  font-weight: 600;
}

.body-cell {
  color: #606266;
  line-height: 1.5;
}
</style>